﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AcfunUpload
{
    public static class Utils
    {
        public static void console(int i,string s)
        {
            ConsoleColor c = ConsoleColor.White;
            if(i==1)
            {
                c = ConsoleColor.Green;
            }
            if (i == 2)
            {
                c = ConsoleColor.Red;
            }
            if (i == 3)
            {
                c = ConsoleColor.Yellow;
            }
            if (i == 4)
            {
                c = ConsoleColor.Blue;
            }
            if (i == 5)
            {
                c = ConsoleColor.Cyan;
            }
            Console.ForegroundColor = c;
            Console.WriteLine ("["+DateTime.Now+"]"+s);
        }
        public static void console(ConsoleColor i, string s)
        {
            ConsoleColor c = i;
            Console.ForegroundColor = c;
            Console.WriteLine("[" + DateTime.Now + "]" + s);
        }
        /// <summary>
        /// MD5加密（滋瓷中文）
        /// </summary>
        /// <param name="text">原始数据</param>
        /// <returns></returns>
        public static string getMD5Encrypt(string text)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text, "MD5");
        }
        /// <summary>
        /// 取Unix时间戳（13位）
        /// </summary>
        /// <returns>Unix时间戳</returns>
        public static long getTimestamp()
        {
            return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
        }
        /// <summary>
        /// 取出中间文本（默认从第一个字符开始）
        /// </summary>
        /// <param name="str">欲取出文本</param>
        /// <param name="first">前面文本</param>
        /// <param name="last">后面文本</param>
        /// <returns></returns>
        public static string getSubstr(string str, string first, string last)
        {

            int str1 = str.IndexOf(first, 0);
            int str2 = str.IndexOf(last, str1 + 1);
            if (str1 < 0 || str2 < 0)
            {
                return null;
            }
            else
            {
                str1 = str1 + first.Length;
                str2 = str2 - str1;
                if (str1 < 0 || str2 < 0)
                {
                    return null;
                }
                return str.Substring(str1, str2);
            }

        }
        /// <summary>
        /// 取出中间文本
        /// </summary>
        /// <param name="str">欲取出文本</param>
        /// <param name="first">前面文本</param>
        /// <param name="last">后面文本</param>
        /// <param name="position">从第几个字符开始</param>
        /// <returns></returns>
        public static string getSubstr(string str, string first, string last, int position)
        {

            int str1 = str.IndexOf(first, position);
            int str2 = str.IndexOf(last, str1 + 1);
            if (str1 < 0 || str2 < 0)
            {
                return null;
            }
            else
            {
                str1 = str1 + first.Length;
                str2 = str2 - str1;
                if (str1 < 0 || str2 < 0)
                {
                    return null;
                }
                return str.Substring(str1, str2);
            }

        }
    }
}
